﻿using System;

namespace PortableTPL.ClientSample
{
    class Program
    {
        static void Main()
        {
            TaskScheduler.ProcessorCount = Environment.ProcessorCount;

            Parallel.ForEach(new[]{"toto", "titi"}, Console.WriteLine);

            try
            {
                Parallel.For(0, 10, i =>
                                                    {
                                                        Console.WriteLine(i);

                                                        if (i == 5)
                                                            throw new Exception("erf...");
                                                    });
            }
            catch (AggregateException aggEx)
            {
                foreach (Exception ex in aggEx.InnerExceptions)
                {
                    Console.WriteLine(string.Format("Caught exception '{0}'", ex.Message));
                }
            }
        }
    }
}
